package com.mdh.runerrands.Util;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.mdh.runerrands.pojo.AlipayBean;

/* 支付宝 */
public class AlipayUtil {
    public static String connect(AlipayBean alipayBean) throws AlipayApiException {
 //1、获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(
                AlipayProperties.getKey("gatewayUrl"),//支付宝网关
                AlipayProperties.getKey("app_id"),//appid
                AlipayProperties.getKey("merchant_private_key"),//商户私钥
                "json",
                AlipayProperties.getKey("charset"),//字符编码格式
                AlipayProperties.getKey("alipay_public_key"),//支付宝公钥
                AlipayProperties.getKey("sign_type")//签名方式
                 );
        System.out.println(alipayClient);
        //2、设置请求参数
 AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        System.out.println(alipayRequest);
 //页面跳转同步通知页面路径
//alipayRequest.setReturnUrl(AlipayProperties.getKey("return_url"));
// // 服务器异步通知页面路径
// alipayRequest.setNotifyUrl(AlipayProperties.getKey("notify_url"));
 //封装参数
 alipayRequest.setBizContent(JSON.toJSONString(alipayBean));

 //3、请求支付宝进行付款，并获取支付结果
        AlipayTradePagePayResponse alipayTradePagePayResponse = alipayClient.pageExecute(alipayRequest);
        System.out.println(alipayTradePagePayResponse);
        String result = null;
        //返回付款信息
 return result;
    }
}